from tortoise import Tortoise
from config import TORTOISE_ORM
from log.logger import setup_logger

logger = setup_logger()


class OrmData:
    """
    封装 Tortoise ORM 的初始化与关闭操作
    """

    def __init__(self):
        """
        :param config: TORTOISE_ORM 配置字典
        """
        self.config = TORTOISE_ORM

    async def init(self):
        """
        初始化 Tortoise ORM 连接
        """
        await Tortoise.init(config=self.config)
        logger.info("Tortoise ORM connections initialized.")

    async def close(self):
        """
        关闭 Tortoise ORM 连接
        """
        await Tortoise.close_connections()
        logger.info("Tortoise ORM connections closed.")
